package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.atguigu.jxc.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author ONIE
 * @create 2021/11/25 6:16 下午
 */
@Service
public class SupplierServiceImpl implements SupplierService {
	@Autowired
	private SupplierDao supplierDao;

	@Override
	public PageResult supplierList(Integer page, Integer rows, String supplierrName) {
		PageHelper.startPage(page,rows);
		Page<Supplier> customerPage = supplierDao.supplierList(supplierrName);
		return new PageResult(customerPage.getTotal(),customerPage.getResult());
	}

	@Override
	public void saveBySupplierId(Integer supplierId, Supplier supplier) {

		if (supplierId == null){
			supplierDao.saveSupplier(supplier);
		}else {
			supplierDao.updateById(supplierId,supplier);
		}
	}

	@Override
	public void deleteByIds(String ids) {
		String[] split = ids.split(",");
		supplierDao.deleteByIds(split);
	}
}
